﻿using System;
using System.Collections.Generic;
using System.Text;
using DAL.DateSet.CantavilTableAdapters;
using DAL.DateSet;
using DAL;
namespace BLL.Wrapper
{
    public class CantavilWrapper : CantavilTableAdapter
    {
        public Cantavil.CantavilDataTable getall()
        {
            return GetData();
        }

        public void addARecord(Cantavil.CantavilRow row)
        {
            Insert(row.typeID, row.cantavilName, row.cantavilType, row.cantavilAddress, row.cantavilRemark, row.cantavilPic, row.cantavilDeveloper,row.developDesc,row.cantavilCreator,row.cantavilCreateDate);
        }

        public void deleteByID(int id)
        {
            string sql = "delete from Cantavil where cantavilID = " + id.ToString();
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            helper.initOle();
            helper.delete(sql);
        }

        public void updateARecord(Cantavil.CantavilRow row)
        {
            Cantavil.CantavilDataTable table = GetData();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if(Convert.ToInt32(table.Rows[i]["cantavilID"]) == row.cantavilID)
                {
                    table.Rows[i]["cantavilDeveloper"] = row.cantavilDeveloper;
                    table.Rows[i]["cantavilCreator"] = row.cantavilCreator;
                    table.Rows[i]["cantavilAddress"] = row.cantavilAddress;
                    table.Rows[i]["cantavilCreateDate"] = row.cantavilCreateDate;
                    table.Rows[i]["cantavilName"] = row.cantavilName;
                    table.Rows[i]["cantavilPic"] = row.cantavilPic;
                    table.Rows[i]["cantavilRemark"] = row.cantavilRemark;
                    table.Rows[i]["cantavilType"] = row.cantavilType;
                    table.Rows[i]["typeID"] = row.typeID;
                    table.Rows[i]["developDesc"] = row.developDesc;
                    break;          
                }
            }
            Update(table);
        }
    }
}
